#include <clusnet/net/TcpDataPacket.h>
#include <gtest/gtest.h>
#include <string>

using namespace clusnet::net;

TEST(TcpDataPacketStream, Test_lvalue_append)
{
    TcpDataPacketStream stream;
    std::string str("hello");
    stream.append(str.c_str(), str.length());
    auto data = stream.data();
    ASSERT_EQ(data.headerLength(), TcpDataPacket::headerLength());
    ASSERT_EQ(data.bodyLength(), str.length());
    ASSERT_EQ(data.dataLength(), data.headerLength() + data.bodyLength());
    ASSERT_STREQ(data.body(), str.c_str());
}

TEST(TcpDataPacketStream, Test_rvalue_append)
{
    TcpDataPacketStream stream;
    std::string str("hello rvalue");
    stream.append(str.c_str(), str.length());
    auto data = std::move(stream).data();
    ASSERT_EQ(data.headerLength(), TcpDataPacket::headerLength());
    ASSERT_EQ(data.bodyLength(), str.length());
    ASSERT_EQ(data.dataLength(), data.headerLength() + data.bodyLength());
    ASSERT_STREQ(data.body(), str.c_str());
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
